import config from '@/config'
import { http } from '@/utils/http'
import { ElMessage } from 'element-plus'

export async function downloadCore(row) {
    const userStore = useUserStore()
    if (row.type == "ChroBrowser") {
        let platform = ''
        if (userStore.packageJs.platform == 'win32') {
            platform = 'win'
        } else if (userStore.packageJs.platform == 'darwin') {
            platform = 'mac'
        }
        let params = {
            system: platform,
            type: row.type == "ChroBrowser" ? 'chromium' : 'firefox',
            version: row.version,
            url: `http://tools.app.qubit-dance.com/version/${row.type == "ChroBrowser" ? 'chromium' : 'firefox'}/${platform}/${row.version}.zip`
        }



        try {

            // window.electron.onDownloadBrowser((event, msg) => {
            //     console.log(msg);
            // })

            const result = await window.electron.downloadBrowser(params)

            // // 监听下载进度
            // ipcRenderer.on('download-progress', (_, { progress: p }) => {
            //     // progress.value = p
            //     console.log(p);

            // })

            // // 触发主进程下载
            // const result = await ipcRenderer.invoke('download-and-extract', {
            //     url: downloadUrl
            // })

            // console.log(`文件已保存到: ${result.path}`);

            // setTimeout(() => {
            //     // progress.value = 0
            // }, 5000)
        } catch (error) {
            console.log(error.message);

            progress.value = 0
        }


    }

}